package jw.hospital.common.exception;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jw.hospital.common.result.ResultCodeEnum;
import lombok.Data;

@Data
@ApiModel(value = "自定义全局异常")
public class HospitalException extends RuntimeException {
    @ApiModelProperty(value = "异常状态码")
    private Integer code;

    //通过状态码和错误信息创建错误对象
    public HospitalException(String message,Integer code) {
        super(message);
        this.code = code;
    }
    //通过枚举类创建错误对象
    public HospitalException(ResultCodeEnum codeEnum) {
      super(codeEnum.getMessage());
      this.code=codeEnum.getCode();
    }

    @Override
    public String toString() {
        return "HospitalException{" +
                "code=" + code +
                '}';
    }
}
